home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / programs / stsemu31 / ymformat.txt < prev   
Text File  |  1996-10-08  |  14KB  |  429 lines

  1.  
  2. ┌┬───────────────────────────────────────────────────────────────────────────┬┐
  3. ├┘                                                                           └┤
  4. │           ██┐ ██┐ █┐   █┐         ██████┐ ██████┐ ██┐     ██████┐           │
  5. │           ██│ ██│ ██┐ ██│         ██┌───┘ └─██┌─┘ ██│     ██┌───┘           │
  6. │           └████┌┘ ██████│         █████┐    ██│   ██│     █████┐            │
  7. │            └██┌┘  ██┌─██│         ██┌──┘    ██│   ██│     ██┌──┘            │
  8. │             ██│   ██│ ██│         ██│     ██████┐ ██████┐ ██████┐           │
  9. │             └─┘   └─┘ └─┘         └─┘     └─────┘ └─────┘ └─────┘           │
  10. │█▀▀▀▄ █▀▀▀█ █▀▀▀▀ █   █ █▄ ▄█ █▀▀▀▀ ██▄ █ ▀▀█▀▀ █▀▀▀█ ▀▀█▀▀  █    █▀▀▀█ ██▄ █│
  11. │██  █ ██  █ ██    ██  █ ██▀ █ ██▀▀  ██▀██   ██  ██▀▀█   ██   ██   ██  █ ██▀██│
  12. │▀▀▀▀  ▀▀▀▀▀ ▀▀▀▀▀ ▀▀▀▀▀ ▀▀  ▀ ▀▀▀▀▀ ▀▀  ▀   ▀▀  ▀▀  ▀   ▀▀   ▀▀   ▀▀▀▀▀ ▀▀  ▀│
  13. │                                                                             │
  14. ├┐               Written by Arnaud Carre. (acarre%siam@cal.fr)               ┌┤
  15. └┴───────────────────────────────────────────────────────────────────────────┴┘
  16.  
  17.  
  18.  
  19.  
  20.     Many people asked me how to find new YM files. Well, the problem is
  21. that it takes me too much time to convert new modules. Then I decide to give
  22. you my YM-File format, so you can generate YM-File by yourself !
  23.  
  24.  
  25.  
  26.     As you probably know, YM is only an YM2149 Chip emulator, not a true
  27. MC68000 emulator. (For the moment !). YM-Files does not contain any 68000
  28. code routine. A music-file is composed of YM2149 registers generated by the
  29. original play-routine for each 50th seconds. As the YM2149 has 14 registers
  30. 8 bits each, that means 14 bytes for 1/50 second, so 700 bytes for one
  31. second of soundchip.
  32.  
  33.     When I convert an ATARI music, I play the music on the ATARI, and I
  34. store YM2149 registers set each 1/50sec (Vertical Blank time, VBL) in a big
  35. file as follow:
  36.  
  37.     VBL1:
  38.         store reg0,reg1,reg2,...,reg12,reg13    (14 regs)
  39.     VBL2:
  40.         store reg0,reg1,reg2,...,reg12,reg13    (14 regs)
  41.  
  42.  
  43.                 ..........
  44.  
  45.  
  46.     VBLn:
  47.         store reg0,reg1,reg2,...,reg12,reg13    (14 regs)
  48.  
  49.  
  50.     The problem is that is takes a lot of disk-space. Just count: A 10
  51. minutes song will take 420000 bytes on disk. But don't panic, the music are
  52. compressed with LHARC method (using LHA program from Haruyasu Yoshizaki).
  53. To reach best compression ratio, I store registers in a different order:
  54.  
  55.  
  56.     VBL1 reg0, VBL2 reg0, VBL3 reg0 .... VBLn reg0
  57.  
  58.     VBL1 reg1, VBL2 reg1, VBL3 reg1 .... VBLn reg1
  59.  
  60.  
  61.                 ..........
  62.  
  63.  
  64.     VBL1 reg14,VBL2 reg14,VBL3 reg14.... VBLn reg14
  65.  
  66.  
  67.  
  68.         So, here is the old YM3 file format:
  69.  
  70.  
  71.     Offset    Size    Name    Value   Comments
  72.     0    4    ID    'YM3!'    File type Identificator.
  73.  
  74.     then YM2149 registers starts a offset 4.
  75.  
  76.     The number of used VBL for music can be computed as follow:
  77.  
  78.     nvbl = (ymfile_size-4)/14;
  79.  
  80.  
  81. ------------------------------------------------------------------------------
  82. WARNING:
  83.     The LHA compression must be called AFTER the file is generated. ALWAYS
  84.     USE THE HEADER TYPE 0 when compressing (-h0).
  85.     Ex: You just create your binary file, starting with 'YM3!' ID, then
  86.     all YM registers. The music is 2 minutes long, that means your
  87.     binary is 2*60*700 + 4 = 84004 bytes long. you must compress it before
  88.     using the file with YM.EXE: (ex: your binary is TEST.BIN)
  89.  
  90.     LHA a -h0 TEST.LHA TEST.BIN
  91.  
  92.     Then a file TEST.LHA is created, wich is DIRECTLY a valid YM file.
  93.     just type:
  94.  
  95.     ren test.lha test.ym
  96.  
  97.     Then you can hear the file with YM.EXE
  98.  
  99.         (I use LHA.EXE v2.13).
  100. ------------------------------------------------------------------------------
  101.  
  102.  
  103. ------------------------------------------------------------------------------
  104. WARNING:
  105.     Some old and specific music starts with header 'YM2!', don't use this
  106.     ID.
  107. ------------------------------------------------------------------------------
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. SPECIAL: Register 13 !
  115. ----------------------
  116.  
  117.     Creating a binary with YM registers for each VBL is easy. However
  118. there is special case concerning register 13. Reg13 is used for the volume
  119. envelope wave-form on the YM2149. The problem is writing to that register
  120. "restarts" the wave-form at beginning. That is, you CAN'T access this regis-
  121. ter each VBL if the original play-routine does not. So, if the original
  122. player does not write to register 13 on VBL n, write 0xff value.
  123. (So when YM.EXE read 0xff as reg13, the internal emulator register is not
  124. updated).
  125.  
  126.  
  127. That's all for 'YM3!' file.
  128. ---------------------------
  129.  
  130.     That's all for the 'YM3!' format. As you see, it is very simple (then
  131. not very powerfull) but you can convert many atari soundchip tunes with that
  132. format. (Especially old game-music, wich use very simple play-routine, or
  133. AMSTRAD CPC music).
  134.  
  135.     But if you know the ATARI demos, you probably know there is many
  136. tricks used by sound-player to produce real-drums or distorted sound: sample
  137. for drums, additional tone synthesis using TIMER etc... The 'YM3!' format can
  138. not play such music so...
  139.  
  140.  
  141.  
  142.  
  143.  
  144. ┌┬───────────────────────────────────────────────────────────────────────────┬┐
  145. ├┘                                                                           └┤
  146. │                       ██┐ ██┐ █┐   █┐ ██┐                                   │
  147. │                       ██│ ██│ ██┐ ██│ ██│██┐                                │
  148. │                       └████┌┘ ██████│ ██████┐                               │
  149. │                        └██┌┘  ██┌─██│ └──██┌┘                               │
  150. │                         ██│   ██│ ██│    ██│                                │
  151. │                         └─┘   └─┘ └─┘    └─┘                                │
  152. │      █   █ █▀▀▀█ ██▀▀▀       █▀▀█  █▀▀▀█ █▀▀▀█ ██▄ █                        │
  153. │      ██▀▄█ ██▀▀█ ▀▀▀▀█       ██▀▀█ ██  █ ██▀█▀ ██▀██  ▄▄    ▄▄    ▄▄        │
  154. │      ▀   ▀ ▀▀  ▀ ▀▀▀▀▀       ▀▀▀▀▀ ▀▀▀▀▀ ▀▀  ▀ ▀▀  ▀  ▀▀    ▀▀    ▀▀        │
  155. │                                                                             │
  156. ├┐                                                                           ┌┤
  157. └┴───────────────────────────────────────────────────────────────────────────┴┘
  158.  
  159.  
  160.     The 'YM4!' format is not currently implemented in the YM emulator, but
  161. I have written the most complete format to play all "evoluated" music such as
  162. SCAVENGER or ETERNAL tunes. If you convert a music wich the player does not use
  163. any "hardware" trick such digi-drum or synth-tune, use 'YM3!' format describe
  164. above: it will be faster and easyer to create. (Almost all standart YM file
  165. existing around the world (exept DIGI-Drums ones) can be written in YM3
  166. format).
  167.  
  168.     If you want to convert a SPECIAL music wich use many tricks to produce
  169. strange sound, you must be familiar with ATARI-ST sound programing and follow
  170. next instructions...
  171.  
  172.  
  173.  
  174.  
  175. Additional sound effects used by strange-player are only two types differents:
  176.  
  177.  
  178.  
  179. 1) Digi-Drums
  180. --------------
  181.  
  182.  
  183.     Generally digi-drums is a bunch of sample in the orignal play-rout.
  184. You will have to localize and extract them. In the YM file, you have to
  185. store the sample with their respective size. (see next part)
  186.         when playing, a digi-drum is defined with one value: timer frequency
  187. to replay sample.
  188.  
  189.  
  190.  
  191. 2) Tone synthesis
  192. -----------------
  193.  
  194.  
  195.     To produce very funny sound, some player use the ATARI-ST timer
  196. controller to change YM2149 volume more than 1 time per VBL. Generally
  197. the routine in the player is as follow:
  198.  
  199. lab1:    move.l    #$08000f00,$ffff8800.w
  200.     move.l    #lab2,$134.w
  201.     rte
  202.  
  203. lab2:    move.l    #$08000000,$ffff8800.w
  204.     move.l    #lab1,$134.w
  205.     rte
  206.  
  207.     So the volume is set to 15 then to 0 then to 15 etc... many times
  208. in the same VBL at a given frequency. In fact, the volume switch always
  209. between 0 and vmax. So a tone-synthesis is define by two values: vmax and
  210. timer frequency.
  211.  
  212.  
  213.  
  214. 3) 'YM4!' File format:
  215. ----------------------
  216.  
  217.  
  218.     Here is the description of the binary YM4 file. After the file is
  219. created, you can compress it with LHA -h0 as above.
  220.  
  221.  
  222.     Legend:    BYTE        8bits integer.
  223.         WORD         16bits integer.
  224.         DWORD        32bits integer.
  225.         string[n]    Ascci string of n bytes long.
  226.         NT-String    NULL-Terminated string.
  227.  
  228.  
  229.         WARNING: All DWORD or WORD are strored in MOTOROLA order in the file
  230.          (INTEL reverse)
  231.  
  232.  
  233.  
  234.  
  235.     Offset    Size    Type        Comment
  236.     0    4    DWORD        ID of YM4 format. ('YM4!')
  237.     4    8    string[8]    Check String ('LeOnArD!')
  238.     12    4    DWORD        Nb of valid VBL of the file.
  239.     16    4    DWORD        Song attributes (see bellow)
  240.     20    2    WORD        Nb of digi-drum sample (can be 0)
  241.  
  242.     For each digidrum sample:
  243.     {
  244.     ..    4    DWORD        sample size
  245.         ..      ?       BYTES           sample data (8bits per sample)
  246.     }
  247.  
  248.     ..    ?    NT-String    Name of the song.
  249.     ..    ?    NT-String    Name of the author.
  250.     ..    ?    NT-String    Comments
  251.     ..    ?            All YM2149 registers.
  252.     ..    4    DWORD        End-File check. ('End!')
  253.  
  254.  
  255.  
  256.     So you've seen in the YM3 format that all 14 registers of the YM2149
  257. are saved in file each VBL. Now, I had to add 2 "virtual" registers to store
  258. extended information. So there is 16 bytes in the file for each VBL. Now the
  259. VBL number n will be noticed "Vn" and register m "Rm". First VBL is V0 and
  260. first register is R0. (R0 to R15)
  261.  
  262.     The file data block will be composed of:
  263.  
  264.     V0R0,V0R1,V0R2,....,V0R14,V0R15
  265.     V1R0,V1R1,V1R2,....,V1R14,V1R15
  266.     .....
  267.         This is the non-interleaved format block.
  268.  
  269.  
  270.  
  271.     The data block can be on a different form:
  272.  
  273.     V0R0,V1R0,V2R0,....,VnR0
  274.     V0R1,V1R1,V2R1,....,VnR1
  275.     ....
  276.     V0R15,V1R15,V2R15,....,VnR15
  277.  
  278.     This is the interleaved format block.
  279.  
  280.     Those who are reading till now have noticed that the YM3 format is
  281. an interleaved format. In fact, the YM4 format can be interleaved or not.
  282. (Interleaved format offers a very powerfull compression ratio when compressed
  283. with LHA).
  284.  
  285.  
  286.  
  287.     Let's see the DWORD "song attribute":
  288.     (bn represent the bit n of the DWORD)
  289.  
  290.     b0:    Set if Interleaved data block.
  291.     b1:    Set if the digi-drum samples are signed data.
  292.  
  293.         b2-b31: Not used yet, MUST BE 0.
  294.  
  295.     Here come valid bits for standard 14 first registers:
  296.     (Same as YM3 Format.)
  297.     (- means Unused, X means used)
  298.  
  299.     NOTE: Now, digi-drum will be noticed DD and Timer-Synth will be
  300.           noticed TS. 
  301.  
  302.  
  303.  
  304.         b7 b6 b5 b4 b3 b2 b1 b0
  305.     r0:      X  X  X  X  X  X  X  X        Period voice A
  306.     r1:     -  -  -  -  X  X  X  X          "      "   "
  307.     r2:      X  X  X  X  X  X  X  X        Period voice B
  308.     r3:     -  -  -  -  X  X  X  X          "      "   "
  309.     r4:      X  X  X  X  X  X  X  X        Period voice C
  310.     r5:     -  -  -  -  X  X  X  X          "      "   "
  311.     r6:     -  -  -  X  X  X  X  X        Noise period
  312.     r7:      X  X  X  X  X  X  X  X        Mixer control
  313.     r8:     -  -  -  X  X  X  X  X        Volume voice A
  314.     r9:     -  -  -  X  X  X  X  X        Volume voice B
  315.     r10:     -  -  -  X  X  X  X  X        Volume voice C
  316.     r11:     X  X  X  X  X  X  X  X        Waveform period.
  317.     r12:     X  X  X  X  X  X  X  X           "       "
  318.     r13:     -  -  -  -  X  X  X  X        Waveform shape.
  319.  
  320.     New "virtual" registers to store extra data:
  321.  
  322.     r14:     -  -  -  -  -  -  -  -        Frequency for DD1 or TS1.
  323.     r15:     -  -  -  -  -  -  -  -        Frequency for DD2 or TS2.
  324.  
  325.  
  326.     As we've seen, r13 has a particular status. If the value stored in
  327. the file is 0xff, YM emulator will not reset the waveform position.
  328.  
  329.     The YM4 format provides to start or run 1 TS and 1 DD during the
  330. same VBL.
  331.  
  332.  
  333.     You notice there is a least 28 free bits in the 14 standard
  334. registers. YM4 format use them to store "extra" information. Let's see
  335. the "extra" bits:
  336.  
  337.  
  338.  
  339.  
  340.     r1 free bits are used to code TS:
  341.     r1 bits b5-b4 is a 2bits code wich means:
  342.  
  343.     00:    No TS.
  344.     01:    TS running on voice A
  345.     10:    TS running on voice B
  346.     11:     TS running on voice C
  347.  
  348.     r1 bit b6 is only used if there is a TS running. If b6 is set, YM
  349. emulator must restart the TIMER to first position. (You must be VERY sound-
  350. chip specialist to hear the difference).
  351.  
  352.     r3 free bits are used to code a DD start.
  353.     r3 b5-b4 is a 2bits code wich means:
  354.  
  355.     00:    No DD
  356.     01:    DD starts on voice A
  357.     10:    DD starts on voice B
  358.     11:    DD starts on voice C
  359.  
  360.  
  361. WARNING:If a DD starts on voice V , the volume register corresponding to V
  362. (Ex r8 for voice A, r9 for B and r10 for C) contains the sample number in
  363. 8 bits.
  364.  
  365.  
  366.  
  367.     Concerning DD and TS, both effects need to be played at a given
  368. frequency. On the ATARI-ST, play routine use the MFP-TIMER chip. That is,
  369. any frequency can be coded on 13bits: 8bits for timer count, and 3bits
  370. for timer predivisor. The MFP runs at 2457600 Hz and has a preset of
  371. predivisor:
  372.  
  373.     000:    Timer stop.
  374.     001:    Prediv by 4
  375.     010:    Prediv by 10
  376.     011:    Prediv by 16
  377.     100:    Prediv by 50
  378.     101:    Prediv by 64
  379.     110:    Prediv by 100
  380.     111:    Prediv by 200
  381.  
  382.     The 8 bits timer count value is named TC and 3bits prediv value
  383.     is named TP.
  384.  
  385.     Some ex to endserstand how it works:
  386.  
  387.     TP    TC    Frequency (Hz)
  388.     1    28    (2457600/4)/28   = 21942 Hz
  389.     4    150    (2457600/50)/150 = 327 Hz
  390.  
  391.  
  392.  
  393. Encode:
  394. -------
  395.     TP for TS is stored in the 3 free bits of r6 (b7-b5)
  396.     TP for DD is stored in the 3 free bits of r8 (b7-b5)
  397.     TC for TS is stored in the 8 bits of r14
  398.     TC for DD is stored in the 8 bits of r15
  399.  
  400.     4bits volume value (vmax) for TS is stored in the 4 free bits of r5
  401. (b7-b4)
  402.  
  403.  
  404.  
  405. 4) Pfff....
  406. -----------
  407.  
  408.         That's all for the YM4 format wich allow you to encode most
  409. of the demo-soundchip from the ATARI. If some of you think the file format is
  410. a bit hard to assume I agree with you. I only prefer a complex but shorter
  411. format than simple and big one...
  412.  
  413.     If you have any trouble, problem or questions about YM3 or YM4 format,
  414. write or mail me:
  415.  
  416. Internet E-Mail:
  417.     acarre%siam@cal.fr
  418.  
  419. French "Minitel"
  420.     3615 RTEL bal "LEONHARD" (with a H)
  421.  
  422.  
  423. ------------------------------------------------------------------------------
  424.  
  425.                 Have a nice day !
  426.  
  427. ------------------------------------------------------------------------------
  428.  
  429.